<?php
/**
 * Comment enter form
 *
 * @author user
 */
class Blog_CommentForm extends Zend_Form
{
    public function init()
    {
        $this->setMethod('post');
        
        //$this->setAction($this->getView()->url(array('action'=>'index')));

        $blogComment = new Blog_Post();

        $this->addElement('hidden', 'post_id');

        $nick_definition = $blogComment->getTable()->getColumnDefinition('nick');
        $this->addElement('text', 'nick', array(
            'label'      => 'blog comment nick',
            'required'   => true,
            'filters'    => array('StringTrim'),
            'validators' => array(
                array('validator' => 'StringLength', 'options' => array(0, $nick_definition['length']))
            )
        ));

        $email_definition = $blogComment->getTable()->getColumnDefinition('email');
        $this->addElement('text', 'email', array(
            'label'      => 'blog comment email',
            'required'   => true,
            'filters'    => array('StringTrim'),
            'validators' => array(
                'EmailAddress',
                array('validator' => 'StringLength',
                      'options' => array(0, $email_definition['length']))

            )
        ));

        $content_definition = $blogComment->getTable()->getColumnDefinition('content');
        $this->addElement('textarea', 'content', array(
            'label'      => 'blog comment content',
            'required'   => true,
            'validators' => array(
                array('validator' => 'StringLength', 'options' => array(0, $content_definition['length']))
            )
        ));

        $this->addElement('captcha', 'captcha', array(
            'label'      => 'please enter the 5 letters displayed below:',
            'required'   => true,
            'captcha'    => array('captcha' => 'Figlet', 'wordLen' => 5, 'timeout' => 300, 'font' => DATA_PATH . '/fonts/big.flf')
        ));

        $this->addElement('submit', 'submit', array(
            'label'    => 'add comment',
        ));
    }
}
